package org.neframework.webtest.action.role.role;

import java.util.List;
import java.util.Map;

import org.neframework.webtest.base.BaseController;
import org.neframework.webtest.model.t_fk_role;
import org.neframework.webtest.service.RoleService;

import com.tmsps.neframework.core.utils.JsonTools;
import com.tmsps.neframework.mvc.annotation.Controller;
import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.annotation.ResponseBody;
import com.tmsps.neframework.mvc.plugin.Tip;

@Controller
@RequestMapping("/cp/role/role")
public class RoleController extends BaseController {

	private static final RoleService rService = new RoleService();

	@RequestMapping("/list")
	public String list() {
		return "/jsp/role/role/list.jsp";
	}

	@RequestMapping("/list_data")
	@ResponseBody
	public void list_data(String srh_uname) {

		List<Map<String, Object>> list = rService.selectRoleList(srh_uname, sort_params, page);

		result.put("list", list);
	}

	@RequestMapping("/add")
	@ResponseBody
	public void add(t_fk_role role) {
		oc.saveObj(role);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/edit_form")
	@ResponseBody
	public String edit_form(String kid) {
		t_fk_role role = (t_fk_role) oc.findObjById(kid, t_fk_role.class);
		return JsonTools.toJson("role", role);
	}

	@RequestMapping("/edit")
	@ResponseBody
	public void edit(t_fk_role role) {
		t_fk_role roleDb = (t_fk_role) oc.findObjById(role.getKid(), t_fk_role.class);
		roleDb.setName(role.getName());
		roleDb.setAuth_codes(role.getAuth_codes());
		oc.updateObj(roleDb);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/del")
	@ResponseBody
	public void del(String kid) {
		oc.delObjById(kid, t_fk_role.class);

		this.setTipMsg(true, "删除成功!", Tip.Type.success);
	}

}
